﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nanoCMS.Core;
using nanoCMS.Store.Concrete;

namespace nanoCMS.Store.Providers {
	public class StoreProvider {
		private readonly WorldContext _worldContext;
		private StoreEntities entities;
		private StoreEntities Entities {
			get { return entities ?? (entities = new StoreEntities(_worldContext.EntityConnectionString)); }
		}


		public StoreProvider(WorldContext worldContext)
		{
			_worldContext = worldContext;
		}

		public StoreSetting GetStoreForTenant(int tenantID)
		{
			StoreSetting storeSetting = Entities.StoreSettings.SingleOrDefault(x => x.TenantID == tenantID);
			if (storeSetting == null) throw new Exception("No store is defined for tenantID=" + tenantID);
			return storeSetting;
		}

		//TODO: add edit store
	}
}
